package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.AssignJobVo;
import com.koocloud.electroplatemanage.service.AssignJobService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: electroplatemanage
 * @description: 分配工作控制类
 * @author: zww
 * @create: 2020-09-29 16:26
 */
@RestController
@RequestMapping("/assignjob")
public class AssignJobController {
    static Logger log = Logger.getLogger("assignjob");
    @Autowired
    AssignJobService assignJobService;

    /**
     * @Description:通过pk查询分配工作表一条记录
     * @Param: [pk]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/9/30
     */
    @RequestMapping(value = "/selectByPk", method = RequestMethod.POST, name = "主键查询")
    public ResponseTemplate selectByPk(@RequestParam(name="pkAssignJob") String pk) {
        log.info("分配工作主键查询主键值:"+pk);
        //通过pk查询分配工作表的一条记录
        return assignJobService.selectByPk(pk);
    }

    /**
     * @Description: 查询所有记录 分页,第一操作人/分配工号
     * @Param: [page,limit, operatorOne,assignjobCode]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/9/30
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllData(String page, String limit,AssignJobVo assignJobVo) {
        log.info("分配工作查询所有记录参数page:"+page+"limit:"+limit+"assignJobVo:"+assignJobVo);
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return assignJobService.selectAllData(page,limit,assignJobVo);
    }

    /**
     * 校验填写的分配工作表主键
     * @param assignJobVo
     * @return
     */
    @RequestMapping(value = "/check", method = RequestMethod.POST, name = "校验填写的分配工作表主键")
    public ResponseTemplate check(@RequestBody AssignJobVo assignJobVo) {
        log.info("分配工作校验填写的分配工作表主键参数assignJobVo:"+assignJobVo);
        //校验填写的分配工作表主键
        return assignJobService.check(assignJobVo);
    }


    /**
     *@Description:插入一条记录
     *@Param: [assignJobVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(@RequestBody AssignJobVo assignJobVo) {
        log.info("分配工作插入一条记录参数assignJobVo:"+assignJobVo);
        //插入一条记录
        return assignJobService.insert(assignJobVo);
    }
    /**
     *@Description:批量插入记录
     *@Param: [listAssignJobVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/batchInsert", method = RequestMethod.POST, name = "批量新增数据")
    public ResponseTemplate batchInsert(@RequestBody List<AssignJobVo> listAssignJobVo) {
        log.info("分配工作批量插入记录参数listAssignJobVo:"+listAssignJobVo);
        //批量插入记录
        return assignJobService.batchInsert(listAssignJobVo);
    }
    /**
     *@Description:逻辑删除一条记录
     *@Param: [pk]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(@RequestParam(name="assignjobCode") String pk,@RequestParam(name="deleteFlag") String deleteFlag) {
        log.info("分配工作逻辑删除记录参数pk:"+pk+"deleteFlag:"+deleteFlag);
        //逻辑删除一条记录
        return assignJobService.delete(pk,deleteFlag);
    }
    /**
     *@Description:通过pks批量逻辑删除记录
     *@Param: [listPks]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/batchDeleteByPks", method = RequestMethod.POST, name = "批量逻辑删除记录")
    public ResponseTemplate batchDeleteByPks(@RequestBody List<String> listPks) {
        log.info("分配工作批量逻辑删除记录参数listPks:"+listPks);
        //通过pks批量逻辑删除记录
        return assignJobService.batchDeleteByPks(listPks);
    }
    /**
     *@Description:修改一条记录
     *@Param: [assignJobVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate update(@RequestBody AssignJobVo assignJobVo) {
        log.info("修改一条记录参数assignJobVo:"+assignJobVo);
        //修改一条记录
        return assignJobService.update(assignJobVo);
    }

    /**
     *@Description:  查询用户和工号
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/21
     */
    @RequestMapping(value = "/selectUserJobNum", method = RequestMethod.POST, name = "查询用户和工号")
    public ResponseTemplate selectUserJobNum() {
        //查询用户和工号
        return assignJobService.selectUserJobNum();

    }

    /**
     * 分配工作表的操作人校验
     * @param assignJobVo
     * @return
     */
    @RequestMapping(value = "/opeVerificat", method = RequestMethod.POST, name = "分配工作表的操作人校验")
    public ResponseTemplate opeVerificat(@RequestBody AssignJobVo assignJobVo) {
        log.info("分配工作表的操作人校验参数assignJobVo:"+assignJobVo);
        //分配工作表的操作人校验
        return assignJobService.opeVerificat(assignJobVo);
    }
}